package shaka.db.internal;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.logicalcobwebs.proxool.ProxoolException;
import org.logicalcobwebs.proxool.configuration.JAXPConfigurator;

import shaka.db.provider.IConnectionProvider;
import shaka.db.provider.IProxoolProvider2;

public class ProxoolContainer2 implements IConnectionProvider {
	private final String name;
	private final String alias;

	public ProxoolContainer2(IProxoolProvider2 provider) {
		name = provider.getAlias();
		alias = String.format("proxool.%s", name);
		try {
			JAXPConfigurator.configure(provider.getProxoolXml(), false);
		} catch (ProxoolException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public String getAlias() {
		return name;
	}

	@Override
	public Connection getConnection() throws SQLException {
		return DriverManager.getConnection(alias);
	}

}
